/**
 * @file   1101.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Sun May  9 00:47:56 2021
 * 
 * @brief  PAT 1101:Find the pivot for quick sort
 * 
 * 
 */
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int N;
    cin>>N;
    int arr[100050];
    for(int i=0;i<N;i++){
	cin>>arr[i];
    }
    int maxleft[100050];
    int minright[100050];
    int Min=0x3f3f3f;
    int Max=0;
    for(int i=0;i<N;i++){
	maxleft[i]=(arr[i]>Max);
	Max=max(Max,arr[i]);
    }
    for(int i=N-1;i>=0;i--){
	minright[i]=(arr[i]<Min);
	Min=min(Min,arr[i]);
    }
    vector<int> result;
    for(int i=0;i<N;i++){
	if(minright[i]&&maxleft[i]){
	    result.push_back(arr[i]);
	}
    }
    cout<<result.size()<<endl;
    if(result.size()==0){
	cout<<endl;
	return 0;
    }
    cout<<result[0];
    for(int i=1;i<result.size();i++){
	cout<<" "<<result[i];
    }
    cout<<endl;
}
